import { defineConfig } from "vite"; // 动态配置函数
import vue from "@vitejs/plugin-vue2";
// import VueDevTools from 'vite-plugin-vue-devtools'
import { resolve } from "path";

export default ({ mode }) => {

  //原有的
  // let base = "/manage/v3/";
  // let outDir = "dist";
  // let port = 1588;
  // if (mode === "dev") {
  //   base = "/manage/v3/dev/";
  //   outDir = "distDev";
  //   port = 1567;
  // }

  let base = "";
  let outDir = "dist";
  let port = 1588;
  if (mode === "dev") {
    base = "";
    outDir = "distDev";
    port = 1567;
  }
  return defineConfig({
    plugins: [vue()],
    server: {
      open: true,
      host: '0.0.0.0',
      port, //端口号
      proxy: {
        "/apixdev": {
          target: "https://yimingserver.jiachuangnet.com/",//赵一鸣
          // target: "http://192.168.1.128:8081",
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/apixdev/, ""),
        },
        "/apix": {
          target: "https://jiachuangnet.com/apix",
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/apix/, ""),
        },
      },
    },
    base,
    build: {
      outDir,
      rollupOptions: {
        input: {
          main: resolve(__dirname, "index.html"),
          nested: resolve(__dirname, "nested/index.html"),
        },
      },
    },
    resolve: {
      // 别名
      alias: [
        {
          find: "@",
          replacement: "/src",
        },
        {
          find: "@js",
          replacement: "/src/assets/js",
        },
      ],
    },
    css: {
      // css预处理器
      preprocessorOptions: {
        less: {
          charset: false,
          additionalData: '@import "./src/assets/css/_var.less";',
        },
      },
    },
  });
};
